//
//  AY_BookLianXuAlertView.m
//  AiYue
//
//  Created by boWen on 2023/11/13.
//

#import "AY_BookLianXuAlertView.h"

@interface AY_BookLianXuAlertView ()
@property (nonatomic, strong) UIButton * buqianJibBtn;
@end

@implementation AY_BookLianXuAlertView


- (instancetype)initWithFrame:(CGRect)frame {
    if([super initWithFrame:frame]) {
        [self initWithAllUI];
    }
    return self;
}


- (void)initWithAllUI {
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
    UIView * bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor clearColor] andRadius:YNUM(16) andAddSubView:self];
    [bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
        make.height.mas_offset(YNUM(376));
        make.width.mas_offset(YNUM(300));
    }];
    
    UIImageView * bgImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_qd_lianxu.png") andBg:[UIColor clearColor] andRadius:0.0 andAddSubView:bg_View];
    [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(bg_View);
    }];
    
    UIButton* sureBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:@"会员补签" andFont:[UIFont boldSystemFontOfSize:16] andTitleColor:[UIColor whiteColor] andBg:COLOR(@"#F76B30") andImage:nil andBgImage:nil andTarget:self andAction:@selector(handleBuqianVpAction) andRadius:YNUM(21) andAddSubView:bg_View];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bg_View).offset(YNUM(-119));
        make.left.equalTo(bg_View).offset(YNUM(16));
        make.right.equalTo(bg_View).offset(YNUM(-16));
        make.height.mas_offset(YNUM(40));
    }];
    sureBtn.backgroundColor = [AYTool customJianBianColorWithColor0:COLOR(@"#9B6B47") withColor1:COLOR(@"#1D1B1B") withFrame:CGSizeMake(YNUM(268), YNUM(40)) withType:0];
    
    self.buqianJibBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:[NSString stringWithFormat:@"%@金币补签", kStringUtils(self.rewordNeedjib)] andFont:[UIFont boldSystemFontOfSize:16] andTitleColor:[UIColor whiteColor] andBg:COLOR(@"#F76B30") andImage:nil andBgImage:nil andTarget:self andAction:@selector(handleNeedJinBiAction) andRadius:YNUM(21) andAddSubView:bg_View];
    [self.buqianJibBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sureBtn.mas_bottom).offset(YNUM(19));
        make.left.equalTo(bg_View).offset(YNUM(16));
        make.right.equalTo(bg_View).offset(YNUM(-16));
        make.height.mas_offset(YNUM(40));
    }];
    self.buqianJibBtn.backgroundColor = [AYTool customJianBianColorWithColor0:COLOR(@"#FF9760") withColor1:COLOR(@"#F76B30") withFrame:CGSizeMake(YNUM(268), YNUM(40)) withType:0];
  
    
    UIButton* fangqiBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:@"放弃连签" andFont:[UIFont boldSystemFontOfSize:16] andTitleColor:COLOR(@"#9C5839") andBg:[UIColor clearColor] andImage:nil andBgImage:nil andTarget:self andAction:@selector(handleFangqiAction) andRadius:YNUM(21) andAddSubView:bg_View];
    [fangqiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buqianJibBtn.mas_bottom).offset(YNUM(12));
        make.left.equalTo(bg_View).offset(YNUM(16));
        make.right.equalTo(bg_View).offset(YNUM(-16));
        make.height.mas_offset(YNUM(40));
    }];
}

- (void)setRewordNeedjib:(NSString *)rewordNeedjib {
    _rewordNeedjib = rewordNeedjib;
    [self.buqianJibBtn setTitle:[NSString stringWithFormat:@"%@金币补签", kStringUtils(self.rewordNeedjib)] forState:UIControlStateNormal];
}


// 显示View
- (void)showPopView{
    [[[UIApplication sharedApplication] windows].firstObject addSubview:self];
}

// 隐藏View
- (void)dismissPopView{
    if(self) {
        [self removeFromSuperview];
    }
}


- (void)handleBuqianVpAction {
    [self dismissPopView];
    if(self.buqianVpBlock) {
        self.buqianVpBlock();
    }
}

- (void)handleNeedJinBiAction {
    [self dismissPopView];

    if(self.buqianBlock) {
        self.buqianBlock();
    }
}

- (void)handleFangqiAction {
    [self dismissPopView];
}

@end
